package sifeap.pl.converter.usuarios;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import sifeap.entities.usuarios.Rol;

@FacesConverter(value = "rolConverter")
public class RolConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		if (value.trim().equals("")) {  
            return null;  
        } else {
                Rol rol = new Rol();
                rol.setNombreRol(value);  
                return rol;
        } 
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {
		String valorRetorno = null;
		try {
			if (value instanceof Rol) {
				valorRetorno =  ((Rol) value).getNombreRol();
	        }
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return valorRetorno;
	}

}
